package com.punai.customer.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.core.domain.TreeBo;
import com.punai.common.utils.SecurityUtils;
import com.punai.customer.domain.CusMaterialCuChapter;
import com.punai.customer.mapper.CusMaterialCuChapterMapper;
import com.punai.customer.service.ICusMaterialCuChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 材料章节Service业务层处理
 *
 * @author zxw_
 * @date 2023-01-30
 */
@Service
public class CusMaterialCuChapterServiceImpl extends ServiceImpl<CusMaterialCuChapterMapper,CusMaterialCuChapter> implements ICusMaterialCuChapterService
{
    @Autowired
    private CusMaterialCuChapterMapper cusMaterialCuChapterMapper;

    /**
     * 查询材料章节
     *
     * @param id 材料章节主键
     * @return 材料章节
     */
    @Override
    public CusMaterialCuChapter selectCusMaterialCuChapterById(String id)
    {
        return cusMaterialCuChapterMapper.selectCusMaterialCuChapterById(id);
    }

    /**
     * 查询材料章节列表
     *
     * @param cusMaterialCuChapter 材料章节
     * @return 材料章节
     */
    @Override
    public List<CusMaterialCuChapter> selectCusMaterialCuChapterList(CusMaterialCuChapter cusMaterialCuChapter)
    {
        return cusMaterialCuChapterMapper.selectCusMaterialCuChapterList(cusMaterialCuChapter);
    }

    /**
     * 新增材料章节
     *
     * @param cusMaterialCuChapter 材料章节
     * @return 结果
     */
    @Override
    public int insertCusMaterialCuChapter(CusMaterialCuChapter cusMaterialCuChapter)
    {
            return cusMaterialCuChapterMapper.insert(cusMaterialCuChapter);
    }

    /**
     * 修改材料章节
     *
     * @param cusMaterialCuChapter 材料章节
     * @return 结果
     */
    @Override
    public int updateCusMaterialCuChapter(CusMaterialCuChapter cusMaterialCuChapter)
    {
        return cusMaterialCuChapterMapper.updateById(cusMaterialCuChapter);
    }

    /**
     * 批量删除材料章节
     *
     * @param ids 需要删除的材料章节主键
     * @return 结果
     */
    @Override
    public int deleteCusMaterialCuChapterByIds(String[] ids)
    {
        return cusMaterialCuChapterMapper.deleteCusMaterialCuChapterByIds(ids);
    }

    /**
     * 删除材料章节信息
     *
     * @param id 材料章节主键
     * @return 结果
     */
    @Override
    public int deleteCusMaterialCuChapterById(String id)
    {
        return cusMaterialCuChapterMapper.deleteCusMaterialCuChapterById(id);
    }

    @Override
    public List<TreeBo> selectTreeData() {
        Long companyId = SecurityUtils.getCompanyId();
        List<CusMaterialCuChapter> chapters = cusMaterialCuChapterMapper.selectList(
                Wrappers.<CusMaterialCuChapter>lambdaQuery()
                        .eq(CusMaterialCuChapter::getCompanyId, companyId)
        );
        return TreeBo.convert(chapters);
    }
}
